package com.jckj.core.service.impl;

import com.jckj.core.dao.CmsCategoryMapper;
import com.jckj.core.entity.CmsCategory;
import com.jckj.core.exception.ServiceException;
import com.jckj.core.service.CmsCategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *     栏目实现类
 * </p>
 * @author :liukuan
 * @date :2018-01-26
 */
@Service
@Transactional(readOnly = true,rollbackFor = ServiceException.class)
public class CmsCategorServiceImpl implements CmsCategoryService {

    private static Logger LOGGER = LoggerFactory.getLogger(CmsCategorServiceImpl.class);

    @Autowired
    private CmsCategoryMapper cmsCategoryMapper;


    /**
     * 添加栏目表
     * @param cmsCategory
     * @return
     */
    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int insert(CmsCategory cmsCategory) {
        int num=0;
        try {
            num= cmsCategoryMapper.insert(cmsCategory);
        } catch (Exception e) {
            LOGGER.error("保存栏目信息：%s", e);
            throw new ServiceException("保存栏目信息出错",e);
        }
          return num;
    }

    /**
     * 修改栏目表
     *
     * @param cmsCategory@return
     */
    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int updateById(CmsCategory cmsCategory) {
        int num=0;
        try {
            num=cmsCategoryMapper.updateByPrimaryKey(cmsCategory);
        } catch (Exception e) {
            LOGGER.error("修改栏目信息：%s", e);
            throw new ServiceException("修改栏目信息出错",e);
        }
        return num;
    }

    /**
     * @param id
     * @return
     */
    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int deleteById(String id) {
        int num=0;
        try {
            num=cmsCategoryMapper.deleteByPrimaryKey(id);
        } catch (Exception e) {
            LOGGER.error("删除栏目信息：%s",e);
            throw new ServiceException("删除栏目信息出错",e);
        }
         return num;
    }


}
